﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EmbeddedLanguage
{
    public static class DictionaryEx
    {
        public static Dictionary<K, V> Clone<K, V>(this Dictionary<K, V> Src)
        {
            if(Src == null) return null;
            var returnObj = new Dictionary<K, V>();
            foreach (var kvp in Src)
            {
                returnObj.Add(kvp.Key, kvp.Value);
            }
            return returnObj;
        }

        public static Dictionary<K, V> MergeWith<K, V>(this Dictionary<K, V> LHS, Dictionary<K, V> RHS)
        {
            if (LHS == null) return RHS.Clone();
            if (RHS == null) return LHS;
            foreach (var kvp in RHS)
            {
                LHS[kvp.Key] = kvp.Value;
            }
            return LHS;
        }
    }
}
